package com.liuzh.deviceinfo.card;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.cardview.widget.CardView;
import c.h.a.m0.k;
import c.h.a.z.b;
import java.util.concurrent.RejectedExecutionException;

public class BatteryCard extends CardView {
    public TextView j;
    public TextView k;
    public TextView l;
    public TextView m;
    public TextView n;
    public TextView o;
    public TextView p;
    public BroadcastReceiver q = new a();
    public TextView r;

    public class a extends BroadcastReceiver {
        @SuppressLint({"SetTextI18n"})
        public void onReceive(Context context, Intent intent) {
            if (intent != null) {
                int intExtra = intent.getIntExtra("level", 0);
                int intExtra2 = intent.getIntExtra("voltage", 0);
                int intExtra3 = intent.getIntExtra("temperature", 0) / 10;
                int intExtra4 = intent.getIntExtra("status", -1);
                int intExtra5 = intent.getIntExtra("plugged", -1);
                int intExtra6 = intent.getIntExtra("health", -1);
                String stringExtra = intent.getStringExtra("technology");
                TextView textView = BatteryCard.this.k;
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append(intExtra);
                stringBuilder.append("%");
                textView.setText(stringBuilder.toString());
                BatteryCard.this.l.setText(k.i(intExtra4, context));
                BatteryCard.this.m.setText(k.h(intExtra5, context));
                BatteryCard.this.j.setText(k.g(intExtra6, context));
                BatteryCard.this.n.setText(stringExtra);
                StringBuilder stringBuilder2 = new StringBuilder();
                stringBuilder2.append(intExtra3);
                stringBuilder2.append(BatteryCard.this.getResources().getString(2131690446));
                String stringBuilder3 = stringBuilder2.toString();
                StringBuilder stringBuilder4 = new StringBuilder();
                stringBuilder4.append(intExtra2);
                stringBuilder4.append(BatteryCard.this.getResources().getString(2131690060));
                stringExtra = stringBuilder4.toString();
                BatteryCard.this.o.setText(stringBuilder3);
                BatteryCard.this.p.setText(stringExtra);
                b bVar = new b(this);
                Handler handler = c.h.a.m0.p.a.a;
                try {
                    c.h.a.m0.p.a.c.execute(bVar);
                } catch (RejectedExecutionException unused) {
                }
            }
        }
    }

    public BatteryCard(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        setUseCompatPadding(true);
        FrameLayout.inflate(getContext(), 2131492922, this);
        this.j = (TextView) findViewById(2131296607);
        this.k = (TextView) findViewById(2131296693);
        this.l = (TextView) findViewById(2131297000);
        this.m = (TextView) findViewById(2131296801);
        this.n = (TextView) findViewById(2131297028);
        this.o = (TextView) findViewById(2131297029);
        this.p = (TextView) findViewById(2131297335);
        this.r = (TextView) findViewById(2131296424);
    }

    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        getContext().registerReceiver(this.q, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
    }

    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        getContext().unregisterReceiver(this.q);
    }
}
